<template>
  <page-header-wrapper :title="false">
    <a-card>
      <div class="table-page-search-wrapper">
        <a-form-model :model="queryParam" layout="inline">
          <a-row :gutter="48">
            <a-col :md="6" :sm="24">
              <a-form-model-item label="顾问姓名">
                <a-select
                  show-search
                  v-model="queryParam['filter[adviser_id]']"
                  placeholder="请选择顾问"
                  :filter-option="filterOption"
                >
                  <a-select-option v-for="(item,index) in adviserOpts" :key="index" :value="index">{{item}}</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
            <template v-if="advanced">
              <a-col :md="6" :sm="24">
                <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
                <a-button style="margin-left: 8px" @click="reset">重置</a-button>
              </a-col>
            </template>
          </a-row>
        </a-form-model>
      </div>
      <div class="table-operator">
        <s-table
          bordered
          ref="table"
          :row-key="(record) => record.uid"
          :columns="invoiceColumns"
          :data="invoiceData"
        >
          <template slot="ix" slot-scope="text,record,index">
            {{index + 1}}
          </template>
          <template slot="adviser_name" slot-scope="text, record">
            <a-tag>{{text}}</a-tag><br>
            <a-tag>{{record.group_type}}</a-tag><br>
            <a-tag>{{record.leader_name}}</a-tag>
          </template>
        </s-table>
      </div>
    </a-card>
  </page-header-wrapper>
</template>

<script>
import { STable } from '@/components'
import statsColumns from '@/columns/stats'
import { getInvoiceStats } from '@/api/stats'

export default {
  components: {
    STable
  },
  name: 'StatsInvoice',
  data () {
    return {
      invoiceColumns: statsColumns.invoice,
      invoiceData: parameters => {
        return getInvoiceStats(Object.assign(parameters, this.queryParam)).then(res => {
          this.adviserOpts = res.result.adviser_opts
          return res.result
        })
      },
      advanced: true,
      adviserOpts: {},
      queryParam: {}
    }
  },
  methods: {
    toggleAdvanced () {
      this.advanced = !this.advanced
    },
    reset () {
      this.queryParam = {}
      this.$refs.table.refresh(true)
    },
    filterOption (input, option) {
      return (
        option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
      )
    }
  }
}
</script>

<style scoped>

</style>
